﻿using CatUtils.Utils.Currency.IoUtils;
using CatUtils.Utils.SpecialUtils.Html;
using CatUtilsDll.Utils.Currency.WebUtils;
using System;
using System.Collections.Generic;

namespace SinaImgUpload.SainTool.LocalTool
{
    internal class ClearImg
    {
        /// <summary>
        /// 清理文件夹
        /// </summary>
        /// <param name="FloderPath"></param>
        /// <param name="MinCountText"></param>
        internal void ClearWithFloder(string FloderPath)
        {
            List<string> FoloderList = FloderNameHelper.GetFullFileNameList(FloderPath);
            foreach (string line in FoloderList)
            {
                Console.WriteLine(line);
                ClearSingleFile(line);
            }
        }

        /// <summary>
        /// 清理文件
        /// </summary>
        /// <param name="FilePath"></param>
        public void ClearSingleFile(string FilePath)
        {
            string Content = FileHelper.ReadAllText(FilePath);
            Content = HtmlHelper.RemoveInvalidImgByDownload(Content, "//img", new List<WebHelper.BlockImgInfo> {
                new WebHelper.BlockImgInfo{  FileSize=8308, ImgHeight=360, ImgWidth=480},
                   new WebHelper.BlockImgInfo{  FileSize=0, ImgHeight=0, ImgWidth=0},
                new WebHelper.BlockImgInfo{  FileSize=8844, ImgHeight=480, ImgWidth=360},
                  new WebHelper.BlockImgInfo{  FileSize=8271, ImgHeight=360, ImgWidth=480},
                  new WebHelper.BlockImgInfo{  FileSize=7092, ImgHeight=360, ImgWidth=360}
            });
            string FloderTip = "IMG移除失效";
            if (HtmlHelper.GetImgSrcVlaueList(Content, "//img").Count == 0)
            {
                FloderTip = "全部失效";
            }
            string NewFilePath = FileNameHelper.CreateFileNameWithChildFloder(FilePath, FloderTip);
            FileHelper.WriteText(NewFilePath, Content);
        }
    }
}